package com.aqie.easy.matrix;

/**
 * 883 三维形体投影面积
 */
public class ProjectionArea {
    public int projectionArea(int[][] grid) {
        int N = grid.length;
        int ans = 0;

        for (int i = 0; i < N; i++){
            int bestRow = 0;
            int bestCol = 0;
            for(int j = 0; j < N; j++){
                if (grid[i][j] > 0) ans ++;
                bestRow = Math.max(bestRow, grid[i][j]);
                bestCol = Math.max(bestCol, grid[j][i]);
            }

            ans += bestCol + bestRow;
        }
        return  ans;
    }
}
